package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.common.itemPojo.Item;
import com.hmall.common.searchPojo.Search;
import com.hmall.common.searchPojo.SearchVo;
import com.hmall.item.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService itemService;

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list")
    public PageDTO<Item> selectPage(@RequestParam Integer page, @RequestParam Integer size){
        return itemService.selectPage(page,size);
    }

    /**
     * 根据id查询商品
     * @return
     */
    @GetMapping("/{id}")
    public Item selectById(@PathVariable Long id){
        return itemService.selectById(id);
    }

    /**
     * 新增商品
     */
    @PostMapping
    public void insert(@RequestBody Item item){
        itemService.insert(item);
    }

    /**
     * 上下架
     * @param id
     * @param status
     */
    @PutMapping("/status/{id}/{status}")
    public void upDown(@PathVariable Long id,@PathVariable Integer status){
        itemService.upDuwn(id,status);
    }

    /**
     * 修改商品
     * @param item
     */
    @PutMapping
    public void updateById(@RequestBody Item item){
        itemService.updateById0(item);
    }

    /**
     * 根据id删除
     * @param id
     */
    @DeleteMapping("/{id}")
    public void removeById(@PathVariable Long id){
        itemService.removeById(id);
    }

    /**
     * 过滤项聚合功能
     * @param search
     * @return
     */
    @GetMapping("/search/filters")
    public SearchVo selectFilters (@RequestBody Search search){
        return itemService.selectFilters(search);
    }

    /**
     * 基本搜索功能
     * @param search
     * @return
     */
    @GetMapping("/search/list")
    public PageDTO<Item> selectConditional(@RequestBody Search search){
        return itemService.selectConditional(search);
    }

}
